#!/usr/bin/env bash
set -euo pipefail

# Configurable paths
CONDA_ENV="MOTIP"
DATA_ROOT="/home/yves/MOTIP-Origin/datasets"
CONFIG="/home/yves/MOTIP/configs/r50_deformable_detr_motip_dancetrack.yaml"
MODEL="/home/yves/MOTIP/pretrains/r50_deformable_detr_motip_dancetrack.pth"
LWG_MODEL="/home/yves/MOTIP/pretrains/lwg_dancetrack.pt"

# Activate conda env
if command -v conda >/dev/null 2>&1; then
  eval "$(conda shell.bash hook)"
  conda activate "${CONDA_ENV}"
else
  echo "[ERROR] conda command not found. Please install Conda and try again." >&2
  exit 1
fi

MODE="${1:-baseline}"

PY="python3"
ENTRY="/home/yves/MOTIP/submit_and_evaluate.py"

common_args=(
  --config-path "${CONFIG}"
  --data-root "${DATA_ROOT}"
  --inference-model "${MODEL}"
  --inference-dataset DanceTrack
  --inference-split val
  --inference-mode evaluate
  --inference-group default
  --inference-dtype FP16
)

case "${MODE}" in
  baseline)
    OUT="/home/yves/MOTIP/outputs/dancetrack_eval_baseline_now"
    echo "[RUN] baseline -> ${OUT}"
    "${PY}" "${ENTRY}" \
      "${common_args[@]}" \
      --outputs-dir "${OUT}" \
      --use-lwg False
    ;;

  recom)
    OUT="/home/yves/MOTIP/outputs/dancetrack_eval_lwg_recom_m0.6_b0.4"
    echo "[RUN] lwg recommended (m=0.6, b=0.4) -> ${OUT}"
    "${PY}" "${ENTRY}" \
      "${common_args[@]}" \
      --outputs-dir "${OUT}" \
      --use-lwg True \
      --lwg-model-path "${LWG_MODEL}" \
      --lwg-main-th 0.6 \
      --lwg-buf-th 0.4
    ;;

  low)
    OUT="/home/yves/MOTIP/outputs/dancetrack_eval_lwg_low_m0.2_b0.01"
    echo "[RUN] lwg low-th sanity (m=0.2, b=0.01) -> ${OUT}"
    "${PY}" "${ENTRY}" \
      "${common_args[@]}" \
      --outputs-dir "${OUT}" \
      --use-lwg True \
      --lwg-model-path "${LWG_MODEL}" \
      --lwg-main-th 0.2 \
      --lwg-buf-th 0.01
    ;;

  *)
    echo "Usage: bash ${0} [baseline|recom|low]" >&2
    exit 2
    ;;
esac

LOG_DIR="${OUT}/evaluate/default/DanceTrack/val/r50_deformable_detr_motip_dancetrack"
echo "[INFO] Log: ${LOG_DIR}/log.txt"
echo "[INFO] Metrics: ${LOG_DIR}/tracker/pedestrian_summary.txt"


